<script type="text/javascript">
$(document).ready(function() {
	//////////// status ////////////////////
	$('#status').click(function(){
    	if ($(this).is(":checked"))
    		$(this).val('1');
    	else
    		$(this).val('0');
   });
	//////////////////// tab langague /////////////////
	$('.tab').click(function(){

		$("#content textarea").each(function(){
			tinyMCE.execCommand('mceRemoveControl', true,$(this).attr('id'));
			$(this).hide();
		});
		
		$("#nametour input").each(function(){
			$(this).hide();
		});
		
		var str  =  $(this).attr('id').split('_');
		
		str1 = 'name_' + str[2];
		str2 = 'intro_'+ str[2];
		str3 = 'des_' + str[2];
		str4 = 'promotion_vip_des_' + str[2];
		str5 = 'promotion_all_des_' + str[2];
		
		$('#' + str1).show();
		$('#' + str2).show();
		$('#' + str3).show();
		$('#' + str4).show();
		$('#' + str5).show();
		
		tinyMCE.execCommand('mceAddControl', true,str2);
		tinyMCE.execCommand('mceAddControl', true,str3);
		tinyMCE.execCommand('mceAddControl', true,str4);
		tinyMCE.execCommand('mceAddControl', true,str5);

		var lang = $(this).html();
		$("#content label[class='name_lang']").each(function(){
			$(this).html(lang);
		});
		
		$("#lang_tab label").each(function(){
			$(this).attr('class','tab');
		});
		$(this).attr('class','tab_active');
		
	});
/////////////// check propertise tour ///////////
	$(".propertise input").click(function(){
		var str="";
		$(this).parent().children("input").each(function(){
			if ($(this).is(":checked"))
				str += $(this).val() + "_";
		});
		$("#" + $(this).parent().attr("id") + "s").val(str);
	});
	
//////////////////// Promotion /////////////////
	$("#promotions input").click(function(){
		if ($(this).is(":checked"))
			$("#"+"con_"+$(this).attr('id')).show();
		else
			$("#"+"con_"+$(this).attr('id')).hide();		
	});
//////////////////// date time picker /////////////////	
	$( "#date_all_begin" ).datepicker();
	$( "#date_all_end" ).datepicker();
	$( "#date_vip_begin" ).datepicker();
	$( "#date_vip_end" ).datepicker();
/////////////////MultiCountry Add city/////////////////
	$('#addcity').click(function(){
		$("#multicountrys option:selected").each(function(){
			var id = $(this).val();
			var k = 0;
			$('#multicountryselect option').each(function(){
				if( id ==  $(this).val())
					k++;
			});
			if (k==0)
				$('#multicountryselect').append("<option value='"+$(this).val()+"' >" +$(this).html() + "</option>" );
			else 
				alert( $(this).html()+ " City is Added" );
			
		});
		var str ='' ;
		$('#multicountryselect option').each(function(){
			str+= $(this).val()+'_';
		});
		$("#multicountry").val(str);
	});
	$('#removecity').click(function(){
		$('#multicountryselect option:selected').each(function(){
			$(this).remove();
		});
	});
	$('#countries').click(function(){
		if ($(this).is(":checked"))
			$("#"+"con_"+$(this).attr('id')).show();
		else
			$("#"+"con_"+$(this).attr('id')).hide();	
	});
});
//////////////// change multiCountry ////////////////
function changemulticity()
{
	var str= "" ;
	<?php foreach ($this->city as $city): ?>
	if ("<?php echo $this->escape($city->countryId); ?>"==$('#country').val())
		str+= "<option value='<?php echo $this->escape($city->id); ?>'  ><?php echo $this->escape($city->name_en); ?></option>";
	<?php endforeach; ?>
	$("#multicountrys").html(str);
}
//////////////// change place //////////////////////
function changeplace()
{
	var str="<option value='0' > Please Choose Region </option>";
	var str1="<option value='0' > Please Choose City </option>";
	<?php foreach ($this->region as $region): ?>
		if ("<?php echo $this->escape($region->countryId); ?>"==$('#countryId').val()  )
			str+= "<option value='<?php echo $this->escape($region->id); ?>'  ><?php echo $this->escape($region->name_en); ?></option>";
	<?php endforeach; ?>
	
	<?php foreach ($this->city as $city): ?>
		if (("<?php echo $this->escape($city->countryId); ?>"==$('#countryId').val())&& ("<?php echo $this->escape($city->regionId); ?>"==$('#regionId').val()))
			str1+= "<option value='<?php echo $this->escape($city->id); ?>'  ><?php echo $this->escape($city->name_en); ?></option>";
	<?php endforeach; ?>
	$("#cityId").html(str1);
	$("#cityId").removeAttr('disabled');
	$("#regionId").html(str);
	$("#regionId").removeAttr('disabled');
}
function changecity()
{
	var str1="<option value='0' > Please Choose City </option>";
	<?php foreach ($this->city as $city): ?>
		if (("<?php echo $this->escape($city->countryId); ?>"==$('#countryId').val())&& ("<?php echo $this->escape($city->regionId); ?>"==$('#regionId').val()))
			str1+= "<option value='<?php echo $this->escape($city->id); ?>'  ><?php echo $this->escape($city->name_en); ?></option>";
	<?php endforeach; ?>
	$("#cityId").html(str1);
	$("#cityId").removeAttr('disabled');
}
</script>
<a class="button" style="float: right!important;margin :10px " href="<?php echo $this->url(array('controller'=>'tour','action'=>'tour')); ?>">Back to Tour list</a>
<?php if ($this->alert!=''){ ?>
<label class="success" id="success"  ><?php echo $this->alert; ?></label>
<?php }?><br/><br/><br/>
<form method="post" enctype="multipart/form-data" >
<table id="content" class="addtable" >
	<tr>
		<td width="20%"  >Status</td>
		<td  ><input id='status' value='0' name='status' type="checkbox"/></td>
	</tr>
	<tr>
		<td> Language </td>
		<td id="lang_tab" >
			<label id="tab_name_vi" class="tab" > Việt Nam </label>
			<label id="tab_name_en" class="tab" > English </label>
			<label id="tab_name_ja" class="tab" > Japan </label>
			<label id="tab_name_cn" class="tab" > China </label>
			<label id="tab_name_fr" class="tab" > France </label>
		</td>
	</tr>
	<tr>
		<td width="20%"   >Name tour ( <label class="name_lang" > Việt Nam  </label> ) </td>
		<td id="nametour" >
			<input name='name_vi' id='name_vi' style="width: 400px;" type="text"/>
			<input name='name_en' id='name_en' style="width: 400px;display: none;" type="text"/>
			<input name='name_ja' id='name_ja' style="width: 400px;display: none;" type="text"/>
			<input name='name_cn' id='name_cn' style="width: 400px;display: none;" type="text"/>
			<input name='name_fr' id='name_fr' style="width: 400px;display: none;" type="text"/>
		</td>
	</tr>
	<tr>
		<td width="20%" >Introduction tour ( <label class="name_lang" > Việt Nam  </label> ) </td>
		<td >
			<textarea rows ="5"  name='intro_vi' id='intro_vi' style="width: 400px;"> </textarea>
			<textarea rows ="5" name='intro_en' id='intro_en' style="width: 400px;display: none;" ></textarea>
			<textarea rows ="5" name='intro_ja' id='intro_ja' style="width: 400px;display: none;"></textarea>
			<textarea rows ="5" name='intro_cn' id='intro_cn' style="width: 400px;display: none;" ></textarea>
			<textarea rows ="5" name='intro_fr' id='intro_fr' style="width: 400px;display: none;"></textarea>
		</td>
	</tr>
	<tr>
		<td width="20%"  >Description tour ( <label class="name_lang" > Việt Nam  </label> )  </td>
		<td >
			<textarea rows ="5"  name='des_vi' id='des_vi' style="width: 400px;"> </textarea>
			<textarea rows ="5" name='des_en' id='des_en' style="width: 400px;display: none;" ></textarea>
			<textarea rows ="5" name='des_ja' id='des_ja' style="width: 400px;display: none;"></textarea>
			<textarea rows ="5" name='des_cn' id='des_cn' style="width: 400px;display: none;" ></textarea>
			<textarea rows ="5" name='des_fr' id='des_fr' style="width: 400px;display: none;"></textarea>
		</td>
	</tr>
	<tr>
		<td width="20%"  >Length tour</td>
		<td> Days: <input type="text" name ="length_day" style="width: 300px;"  />  Nights : <input type="text" name ="length_night" style="width: 300px;"  />  </td>
	</tr>
	<tr>
		<td width="20%"  >Price tour</td>
		<td><input type="text" name ="price" style="width: 400px;"  /></td>
	</tr>
	<tr>
		<td width="20%"  >Image tour</td>
		<td><input type="file" name ="imagefile" style="width: 400px;"  /></td>
	</tr>
	<tr>
		<td width="20%"  >Tour Type </td>
		<td >
			<select name="tourtypeId" id="tourtypeId" >
			<option> Please Choose Tour Type </option>
			<?php foreach ($this->tourtype as $tourtype): ?>
				<option value="<?php echo $this->escape($tourtype->id); ?>"  ><?php echo $this->escape($tourtype->name_en); ?></option>
			<?php endforeach; ?>
			</select>
			<input type="checkbox" id="countries" /> MultiCountry
			<div style="display: none;" id="con_countries" >
				<br/><h2 style='color:#8b8c87; font-style: italic;' >MultiCountry</h2>
				<div>
					<select onchange="changemulticity()" id="country" >
					<option> Please Choose Country </option>
					<?php foreach ($this->country as $country): ?>
						<option value="<?php echo $this->escape($country->id); ?>"  ><?php echo $this->escape($country->name_en); ?></option>
					<?php endforeach; ?>
					</select>
				</div>
				<div style="width: 100%;float: left;text-align: center;margin-top: 10px" >
					<div style="width:20%;float: left;"  >
						<h3 style='color:#8b8c87; font-style: italic;' >Chosse City</h3>
						<select id="multicountrys" style="width: 150px" size="8" multiple="multiple" >
					
						</select>
					</div>
					<div style="width:8%;float: left;" >
						<input  class="button" id="addcity" style="margin-left: 15px;margin-top: 90px" type="button" value="add" /><br/><br/>
						<input  class="button" id="removecity" style="margin-top: 10px" type="button" value='remove' />
					</div>
					<div style="width:20%;float: left;text-align: center; " >
						<h3 style='color:#8b8c87; font-style: italic;' >City in Tour</h3>
						<select id="multicountryselect" style="width: 150px" size="8" multiple="multiple" >
					
						</select>
					</div>
				</div>
			</div>
			
			
		</td>
	</tr>
	<tr>
		<td width="20%"  >Country </td>
		<td >
			<select name="countryId" onchange="changeplace()" id="countryId" >
			<option> Please Choose Country </option>
			<?php foreach ($this->country as $country): ?>
				<option value="<?php echo $this->escape($country->id); ?>"  ><?php echo $this->escape($country->name_en); ?></option>
			<?php endforeach; ?>
			</select>
		</td>
	</tr>
	<tr>
		<td width="20%"  >Region </td>
		<td >
			<select name="regionId" disabled="disabled" onchange="changecity()" id="regionId" >
				<option value='0' > Please Choose Region </option>
			</select>
		</td>
	</tr>
	<tr>
		<td width="20%"  >City </td>
		<td >
			<select disabled="disabled" name="cityId" id="cityId" >
			<option value='0' > Please Choose City </option>
			</select>
		</td>
	</tr>
	<tr>
		<td width="20%"  > Priority </td>
		<td >
			<select name="priority" id="priority" >
			<option value="0" > Please Choose Priority </option>
			<option value="1"  >Top</option>
			<option value="2"  >Hight</option>
			<option value="3"  >Medium</option>
			<option value="4"  >Low</option>
			</select>
		</td>
	</tr>
	<!--<tr>
		<td width="20%"  >Date Tour</td>
		<td style="height: 100px" >
		<div id="tab_day" >
		<label id="tab_date_1" class="tab" > Day 1 </label>
		</div><br/>
		<label id="tab_date_vi" class="tab" > Việt Nam </label>
		<label id="tab_date_en" class="tab" > English </label>
		<label id="tab_date_ja" class="tab" > Japan </label>
		<label id="tab_date_cn" class="tab" > China </label>
		<label id="tab_date_fr" class="tab" > France </label>
		<label class="button" id="add_day" style="float: right;" >Add Day</label>
		</td>
	</tr>
	<tr>
		<td width="20%" id="tab_desc" style="padding-left: 50px!important;"  class="tab_content"  >Việt Nam</td>
		<td  class="tab_content" >
		<table>
			<tr>
				<td>
					Title 
				</td>
				<td>
					<input name="title_date[]" id="title_date_1"  type="text" style="width: 400px;" />
				</td>
			</tr>
			<tr>
				<td>
					City
				</td>
				<td>
					<select name="citydateId[]" id="cityId" >
					<option> Please Choose City </option>
					<?php // foreach ($this->city as $city): ?>
						<option value="<?php // echo $this->escape($city->id); ?>"  ><?php // echo $this->escape($city->name_en); ?></option>
					<?php // endforeach; ?>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					Description 
				</td>
				<td id="con_day"  >
					<textarea rows ="5" name='date_vi[]' id='day1_1_vi' style="width: 400px;"> </textarea>
					<textarea rows ="5" name='date_en[]' id='day1_1_en' style="width: 400px;display: none;" ></textarea>
					<textarea rows ="5" name='date_ja[]' id='day1_1_ja' style="width: 400px;display: none;"></textarea>
					<textarea rows ="5" name='date_cn[]' id='day1_1_cn' style="width: 400px;display: none;" ></textarea>
					<textarea rows ="5" name='date_fr[]' id='day1_1_fr' style="width: 400px;display: none;"></textarea>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	--><tr>
		<td width="20%"  >Properties Of Tour</td>
		<td ><table><tr>
			<td class="propertise" id="inclusion" >
				<h2 style='color:#8b8c87; font-style: italic;' >Inclusions</h2>
				<?php foreach ($this->inclusions as $inclusions): ?>
					<input type="checkbox" value="<?php echo $this->escape($inclusions->id); ?>"  />
					<?php echo $this->escape($inclusions->title_en); ?>
					<br/>
				<?php endforeach; ?>
			</td>
			<td class="propertise" id="exclusion" >
				<h2 style='color:#8b8c87; font-style: italic;' >Exclusions</h2>
				<?php foreach ($this->exclusions as $exclusions): ?>
					<input type="checkbox" value="<?php echo $this->escape($exclusions->id); ?>"  />
					<?php echo $this->escape($exclusions->title_en); ?>
					<br/>
				<?php endforeach; ?>
			</td>
			<td class="propertise" id="cancellation" >
				<h2 style='color:#8b8c87; font-style: italic;' >Cancellations</h2>
				<?php foreach ($this->cancellation as $cancellation): ?>
					<input type="checkbox" value="<?php echo $this->escape($cancellation->id); ?>"  />
					<label title="<?php echo $this->escape($cancellation->title_en);?>" ><?php echo substr($this->escape($cancellation->title_en),0,20); if(strlen($this->escape($cancellation->title_en))>30) echo("..."); ?></label>
					<br/>
				<?php endforeach; ?>
			</td>
			<td class="propertise" id="theme" >
				<h2 style='color:#8b8c87; font-style: italic;' >Theme</h2>
				<?php foreach ($this->theme as $theme): ?>
					<input type="checkbox" value="<?php echo $this->escape($theme->id); ?>"  />
					<label title="<?php echo $this->escape($theme->name_en);?>" ><?php echo substr($this->escape($theme->name_en),0,20); if(strlen($this->escape($theme->name_en))>30) echo("..."); ?></label>
					<br/>
				<?php endforeach; ?>
			</td>
		</tr></table></td>
	</tr>
	<tr style="display: none;" >
		<td>content properties</td>
		<td>
			<input name="inclusions" id="inclusions" />
			<input name="exclusions" id="exclusions" />
			<input name="cancellations" id="cancellations" />
			<input name="themes" id="themes" />
			<input name="multicountry" value="0" id="multicountry"/>
		</td>
	</tr>
	<tr id="promotions" >
		<td width="20%"  >Promotions Tour</td>
		<td>
			<input id="promotion" type="checkbox"  />Promotions
			<div id="con_promotion" style="padding-left: 30px;display: none;">Promotions For : <input id="promotion_all" type="checkbox"  /> All Customer <input id="promotion_vip" type="checkbox"  /> Vip Customers</div>
			<div id="con_promotion_all" style="padding-left: 50px;padding-top: 10px;display: none;"  >
				
				<h2 style='color:#8b8c87; font-style: italic;' >Promotion for All Customer</h2>
				<br/>
				<table>
					<tr>
						<td>
							Image
						</td>
						<td>
							<input name="promotion_all_image" type="file" />
						</td>
					</tr>
					<tr>
						<td>
							price
						</td>
						<td>
							<input name="promotion_all_price" type="text" >
						</td>
					</tr>
					<tr>
						<td>
							Time 
						</td>
						<td>
							Begin : <input type="text" id="date_all_begin" name="promotion_all_begin" /> end : <input type="text" id="date_all_end" name="promotion_all_end" />
						</td>
					</tr>
					<tr>
						<td>
							Description<br/> ( <label class="name_lang" > Việt Nam  </label> )
						</td>
						<td>
							<textarea rows ="5" name='promotion_all_des_vi' id='promotion_all_des_vi' style="width: 400px;"> </textarea>
							<textarea rows ="5" name='promotion_all_des_en' id='promotion_all_des_en' style="width: 400px;display: none;" ></textarea>
							<textarea rows ="5" name='promotion_all_des_ja' id='promotion_all_des_ja' style="width: 400px;display: none;"></textarea>
							<textarea rows ="5" name='promotion_all_des_cn' id='promotion_all_des_cn' style="width: 400px;display: none;" ></textarea>
							<textarea rows ="5" name='promotion_all_des_fr' id='promotion_all_des_fr' style="width: 400px;display: none;"></textarea>
						</td>
					</tr>
				</table>
			</div>
			<div id="con_promotion_vip" style="padding-left: 50px;padding-top: 10px;display: none;">
			<h2 style='color:#8b8c87; font-style: italic;' >Promotion for Vip Customer</h2>
				<br/>
				<table>
					<tr>
						<td>
							Image
						</td>
						<td>
							<input name="promotion_vip_image" type="file" />
						</td>
					</tr>
					<tr>
						<td>
							price
						</td>
						<td>
							<input name="promotion_vip_price" type="text" >
						</td>
					</tr>
					<tr>
						<td>
							Time 
						</td>
						<td>
							Begin : <input type="text" id="date_vip_begin" name="promotion_vip_begin" /> end : <input type="text" id="date_vip_end" name="promotion_vip_end" />
						</td>
					</tr>
					<tr>
						<td>
							Description<br/> ( <label class="name_lang" > Việt Nam  </label> )
						</td>
						<td>
							<textarea rows ="5" name='promotion_vip_des_vi' id='promotion_vip_des_vi' style="width: 400px;"> </textarea>
							<textarea rows ="5" name='promotion_vip_des_en' id='promotion_vip_des_en' style="width: 400px;display: none;" ></textarea>
							<textarea rows ="5" name='promotion_vip_des_ja' id='promotion_vip_des_ja' style="width: 400px;display: none;"></textarea>
							<textarea rows ="5" name='promotion_vip_des_cn' id='promotion_vip_des_cn' style="width: 400px;display: none;" ></textarea>
							<textarea rows ="5" name='promotion_vip_des_fr' id='promotion_vip_des_fr' style="width: 400px;display: none;"></textarea>
						</td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
	<tr>
		<td></td>
		<td style=" padding-left: 220px;" >
			<input  style="margin-right: 20px;" class="button" type="submit" value="Add new" / >
			<input id="cleartext" onclick="validation()"   class="button" type="button" value="Clear text" / >
		</td>
	</tr>
	
</table>
</form>